<?php
// application/bootstrap.php

// APPLICATION CONSTANTS - Set the constants to use in this application.
defined('APPLICATION_PATH')
or define('APPLICATION_PATH', dirname(__FILE__));

defined('APPLICATION_ENVIRONMENT')
	or define('APPLICATION_ENVIRONMENT', 'development');

// FRONT CONTROLLER - Get the front controller.
$frontController = Zend_Controller_Front::getInstance();

// CONTROLLER DIRECTORY SETUP - Point the front controller to your action
$frontController->setControllerDirectory(APPLICATION_PATH . '/controllers');

// Set locale for Germany
$locale = new Zend_Locale();
Zend_Registry::set('Zend_Locale', new Zend_Locale($locale->getLanguage()));

// APPLICATION ENVIRONMENT - Set the current environment.
$frontController->setParam('env', APPLICATION_ENVIRONMENT);
//$frontController->registerPlugin(new Aikanet_Plugin_Control());
$frontController->registerPlugin(new Ht_Plugin_Navigation());
$frontController->registerPlugin(new Ht_Plugin_Rightcol());
$frontController->registerPlugin(new Ht_Plugin_Settings());
//$frontController->registerPlugin(new Aikanet_Plugin_Breadcrumbs());
//$frontController->registerPlugin(new Aikanet_Plugin_Language());

//Logcheck
$frontController->registerPlugin(new Ht_Plugin_Logcheck());
//Rollensystem
$acl = new Model_Acl();
$frontController->registerPlugin(new Ht_Plugin_Acl($acl));

// SESSION initialisation
Zend_Session::start();

// LAYOUT SETUP - Setup the layout component
Zend_Layout::startMvc(APPLICATION_PATH . '/layouts/scripts');

// VIEW SETUP - Initialize properties of the view object
$view = Zend_Layout::getMvcInstance()->getView();
$view->doctype('XHTML1_STRICT');
$view->addHelperPath('Ht/View/Helper', 'Ht_View_Helper');

// CONFIGURATION - Setup the configuration object
$configuration = new Zend_Config_Ini(
APPLICATION_PATH . '/config/app.ini',
APPLICATION_ENVIRONMENT
);

// DATABASE ADAPTER - Setup the database adapter
$dbAdapter = Zend_Db::factory($configuration->database);
$dbAdapter->query('SET NAMES utf8');

// REGISTRY - setup the application registry
// An application registry allows the application to store application
// necessary objects into a safe and consistent (non global) place for future
// retrieval.  This allows the application to ensure that regardless of what
// happends in the global scope, the registry will contain the objects it
// needs.
$registry = Zend_Registry::getInstance();
$registry->configuration = $configuration;
$registry->dbAdapter     = $dbAdapter;

// DATABASE TABLE SETUP - Setup the Database Table Adapter
Zend_Db_Table_Abstract::setDefaultAdapter($dbAdapter);

// ROUTING - route to the controller
$router = $frontController->getRouter();

//TRANSLATION
if($_SERVER['SERVER_NAME'] == 'www.busch-jaeger-beschriftungstool.de') {
	$route = new Zend_Controller_Router_Route(
				':language/:controller/:action/*',
					array(
						'module'	 => 'default',
						'controller' => 'index',
						'action'	 => 'index',
						'language'   => 'en'
					)
				);
	$router->addRoute('lang_default', $route);
} else {
	$route = new Zend_Controller_Router_Route(
				':language/:controller/:action/*',
					array(
						'module'	 => 'default',
						'controller' => 'index',
						'action'	 => 'index',
						'language'   => 'de'
					)
				);
	$router->addRoute('lang_default', $route);
}
$route = new Zend_Controller_Router_Route('impressum.html', array('controller'=>'static', 'action'=>'impressum'));
$router->addRoute('impressum',$route);
$route = new Zend_Controller_Router_Route(':language/category/:categoryid/', array('controller'=>'category'));
$router->addRoute('category',$route);
//$route = new Zend_Controller_Router_Route('index.html', array('controller'=>'marking', 'action'=>'preview'));
//$router->addRoute('marking/preview',$route);
$route = new Zend_Controller_Router_Route(':language/profile/activate/:activationurl/:email',array('controller' => 'profile','action' => 'activate'));
$router->addRoute('activate',$route);

// CLEANUP - remove items from global scope
// This will clear all our local boostrap variables from the global scope of
// this script (and any scripts that called bootstrap).  This will enforce
// object retrieval through the Applications's Registry
unset($dbAdapter, $registry);